﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Text.RegularExpressions;
using System.Collections;

using TRPOP.CMS.RegAssembly;
using TRPOP.Common;
using TRPOP.CMS.Plugin;

namespace TRPOP.CMS.Template.GenerateCS
{
    /// <summary>
    ///  Csharp程序文件里用到的通用的方法
    /// </summary>
    public class CommonMethord
    {

        #region 基本的方法

        /// <summary>
        /// 字符串特殊替换
        /// </summary>
        /// <param name="strSource"></param>
        /// <returns></returns>
        public static string ConvertSpecialChar(string strSource)
        {
            return strSource.Replace("\\", "\\\\").Replace("\"", "\\\"");
        }
        /// <summary>
        /// 初始化页面变量PageInfo
        /// </summary>
        /// <param name="oTemplatePageInfo"></param>
        /// <returns></returns>
        public static DataRow InitPageInfo(TemplateDllPageInfo oTemplatePageInfo)
        {
            DataTable oTable = new DataTable();

            oTable.Columns.Add("TotalNum");
            oTable.Columns.Add("TotalPage");
            oTable.Columns.Add("CurrentPage");
            oTable.Columns.Add("PageNum");
            oTable.Columns.Add("URL");
            oTable.Columns.Add("PageList");
            oTable.Columns.Add("SearchKeys");

            DataRow oPageInfo = oTable.NewRow();

            oPageInfo["TotalNum"] = 0;
            oPageInfo["TotalPage"] = 0;
            oPageInfo["CurrentPage"] = 0;
            oPageInfo["PageNum"] = 0;
            oPageInfo["URL"] = 0;
            oPageInfo["PageList"] = 0;
            oPageInfo["SearchKeys"] = oTemplatePageInfo.strSearchPageKeys;

            return oPageInfo;
        }
        #endregion

        #region 从数据池中获取值

        /// <summary>
        /// 获取变量的值
        /// </summary>
        /// <param name="strDataSet">变量集合</param>
        /// <param name="strIndex">索引位置</param>
        /// <param name="strVar">变量key</param>
        /// <param name="oDictionaryTable">保存Table的变量库</param>
        /// <param name="oDictionaryRow">保存的Row变量库</param>
        /// <param name="oDictionaryObj">保存的Obj变量库</param>
        /// <param name="oTemplatePageInfo">当前dll模板赋予的实体</param>
        /// <param name="strCurrenContent">当前信息内容所对应的key</param>
        /// <param name="m_IDAL">获取模板变量的方法</param>
        /// <returns></returns>
        public static string GetTagValue(string strDataSet, string strIndex, string strVar, Dictionary<string, DataTable> oDictionaryTable, Dictionary<string, DataRow> oDictionaryRow, Dictionary<string, object> oDictionaryObj, TemplateDllPageInfo oTemplatePageInfo, string strCurrenContent, IDAL m_IDAL)
        {
            string strReturn = string.Empty;
            int intIndex = strIndex.ToInt();
            if (strVar.IsEmpty())
            {
                //如果为空，则直接返回空
            }
            else if (intIndex == 0 && strIndex.IsEmpty() && strDataSet.IsEmpty())//[$var]
            {
                if (strVar.ToLower() == oTemplatePageInfo.strContentMainFied.ToLower())
                {//如果是内容字段,则将标签替换为<content>,方便在最后处理的时候生成一个或多个页面                    
                    strReturn = "<" + oTemplatePageInfo.strMainField + ">";
                }
                else if (strVar == "PageList")
                {//内容分页标签
                    strReturn = "<PageList>";
                }
                else if (oDictionaryRow.ContainsKey(strCurrenContent) && oDictionaryRow[strCurrenContent] != null && oDictionaryRow[strCurrenContent].Table.Columns.Contains(strVar))
                {//从当前内容页里的主内容里查找
                    strReturn = oDictionaryRow[strCurrenContent][strVar].ToString();
                }
                else if (oDictionaryObj.ContainsKey(strVar))
                {//从自定义的变量里找
                    strReturn = oDictionaryObj[strVar].ToString();
                }
                else
                {//从系统设置的变量里找
                    strReturn = m_IDAL.GetTemplateVar(strVar);
                }
            }
            else if (intIndex == 0 && strIndex.IsEmpty() && !strDataSet.IsEmpty())//[$var.var]
            {
                if (oDictionaryRow.ContainsKey(strDataSet) && oDictionaryRow[strDataSet] != null && oDictionaryRow[strDataSet].Table.Columns.Contains(strVar))//行变量里有该数据
                {
                    strReturn = oDictionaryRow[strDataSet][strVar].ToString();
                }
                else if (oDictionaryTable.ContainsKey(strDataSet) && oDictionaryTable[strDataSet] != null && oDictionaryTable[strDataSet].Columns.Contains(strVar) && oDictionaryTable[strDataSet].Rows.Count == 1)
                {
                    strReturn = oDictionaryTable[strDataSet].Rows[0][strVar].ToString();
                }
            }
            else if (!strIndex.IsEmpty() && !strDataSet.IsEmpty())//[$var.0.var]  [$var.1.var]
            {
                if (oDictionaryTable.ContainsKey(strDataSet) && oDictionaryTable[strDataSet] != null && oDictionaryTable[strDataSet].Columns.Contains(strVar) && oDictionaryTable[strDataSet].Rows.Count > intIndex)
                {
                    strReturn = oDictionaryTable[strDataSet].Rows[intIndex][strVar].ToString();
                }
                else if (intIndex == 0 && oDictionaryRow.ContainsKey(strDataSet) && oDictionaryRow[strDataSet] != null && oDictionaryRow[strDataSet].Table.Columns.Contains(strVar))
                {
                    strReturn = oDictionaryRow[strDataSet][strVar].ToString();
                }
            }
            return strReturn;
        }

        /// <summary>
        /// 根据name获取DataTable
        /// </summary>
        /// <param name="strName"></param>
        /// <param name="oDictionaryTable"></param>
        /// <param name="oDictionaryRow"></param>
        /// <returns></returns>
        public static DataTable GetDtByKeyName(string strName, Dictionary<string, DataTable> oDictionaryTable, Dictionary<string, DataRow> oDictionaryRow)
        {
            DataTable oTable = null;
            if (oDictionaryTable.ContainsKey(strName))
            {
                oTable = oDictionaryTable[strName];
            }
            else if (strName.Contains("."))
            {
                string strRow = strName.Split('.')[0];
                string strColumn = strName.Split('.')[1];
                if (oDictionaryRow.ContainsKey(strRow) && oDictionaryRow[strRow].Table.Columns.Contains(strColumn))
                {
                    if (oDictionaryRow[strRow][strColumn] is DataTable)
                        return oDictionaryRow[strRow][strColumn] as DataTable;
                    else
                        return new DataTable();
                }
            }
            if (oTable == null)
                return new DataTable();
            return oTable;
        }

        #endregion

        #region 往数据池填充值

        /// <summary>
        /// 设定某变量的值
        /// </summary>
        /// <param name="strName"></param>
        /// <param name="objValue"></param>
        /// <param name="?"></param>
        /// <param name="oTemplatePageInfo"></param>
        /// <param name="oDictionaryObj"></param>
        public static void SaveVar(string strName, object objValue, TemplateDllPageInfo oTemplatePageInfo, Dictionary<string, object> oDictionaryObj)
        {
            //图片资源类型
            if (ImgType.strPageTypeVarName == strName)
            {
                oTemplatePageInfo.oImgResourceType = ImgType.GetTypeByPageTypeVar(objValue.ToString());
            }

            if (oDictionaryObj.ContainsKey(strName))
            {
                oDictionaryObj[strName] = objValue;
            }
            else
                oDictionaryObj.Add(strName, objValue);

        }

        /// <summary>
        /// 预设值的变量
        /// </summary>
        /// <param name="oTemplatePageInfo"></param>
        /// <param name="oDictionaryObj"></param>
        public static void InitPageVar(TemplateDllPageInfo oTemplatePageInfo, Dictionary<string, object> oDictionaryObj)
        {
            foreach (KeyValuePair<string, string> oTemp in oTemplatePageInfo.oPageVars)
            {
                if (oDictionaryObj.ContainsKey(oTemp.Key))
                {
                    oDictionaryObj[oTemp.Key] = oTemp.Value;
                }
                else
                {
                    oDictionaryObj.Add(oTemp.Key, oTemp.Value);
                }
            }
        }

        /// <summary>
        /// 设定某行数据到 DataRow 库中
        /// </summary>
        /// <param name="strName"></param>
        /// <param name="oDataRow"></param>
        /// <param name="oDictionaryRow"></param>
        public static void SaveRow(string strName, DataRow oDataRow, Dictionary<string, DataRow> oDictionaryRow)
        {
            if (oDictionaryRow.ContainsKey(strName))
            {
                oDictionaryRow[strName] = oDataRow;
            }
            else
                oDictionaryRow.Add(strName, oDataRow);
        }

        /// <summary>
        /// 设定某行数据到 DataRow 库中
        /// </summary>
        /// <param name="strName"></param>
        /// <param name="oTable"></param>
        /// <param name="oDictionaryTable"></param>
        public static void SaveTable(string strName, DataTable oTable, Dictionary<string, DataTable> oDictionaryTable)
        {
            if (oDictionaryTable.ContainsKey(strName))
            {
                oDictionaryTable[strName] = oTable;
            }
            else
                oDictionaryTable.Add(strName, oTable);
        }

        /// <summary>
        /// CMS标签解析，将解析的数据添加到指定的Dictionary中
        /// </summary>
        /// <param name="strAction">action关键字(大写)</param>
        /// <param name="oAttribute">属性</param>
        /// <param name="oDictionaryTable">DataTable的Dictionary，用于存放解析后的数据</param>
        /// <param name="oDictionaryRow">DataRow的Dictionary，用于存放解析后的数据</param>
        /// <param name="oDictionaryObj">object的Dictionary，用于存放解析后的数据</param>
        /// <param name="oTemplatePageInfo">页面信息，用于存放解析后的数据</param>
        public static void SaveCMSTagData(Dictionary<string, string> oAttribute, Dictionary<string, DataTable> oDictionaryTable, Dictionary<string, DataRow> oDictionaryRow, Dictionary<string, object> oDictionaryObj, TemplateDllPageInfo oTemplatePageInfo)
        {
            if (!oAttribute.ContainsKey("action") || !oAttribute.ContainsKey("return"))
                return;

            string strDataFlag = oAttribute["return"];

            switch (oAttribute["action"].ToUpper())
            {
                case "NODE"://结点信息
                    SaveRow(strDataFlag, CMSTagGetData.GetNodeInfo(oAttribute, oTemplatePageInfo), oDictionaryRow);
                    break;
                case "NODELIST"://节点信息列表
                    SaveTable(strDataFlag, CMSTagGetData.GetNodeInfoList(oAttribute, oTemplatePageInfo), oDictionaryTable);
                    break;
                case "CONTENT"://获取内容信息
                    DataTable oTable = CMSTagGetData.GetContentInfo(oAttribute, oTemplatePageInfo);
                    if (oTable == null)
                        return;
                    if (oTable.Rows.Count > 1 || (oAttribute.ContainsKey("loopmode") && oAttribute["loopmode"] == "1"))
                    {
                        SaveTable(strDataFlag, CMSTagGetData.GetContentInfo(oAttribute, oTemplatePageInfo), oDictionaryTable);
                    }
                    else if (oTable.Rows.Count == 1)
                    {
                        SaveRow(strDataFlag, oTable.Rows[0], oDictionaryRow);
                    }
                    break;
                case "EXTRAPUBLISH"://获取附加发布信息
                    SaveTable(strDataFlag, CMSTagGetData.GetExtraPublish(oAttribute, oTemplatePageInfo), oDictionaryTable);
                    break;
                case "COUNT"://用于对指定条件范围的内容进行计算统计
                    SaveVar(strDataFlag, CMSTagGetData.GetCount(oAttribute, oTemplatePageInfo), oTemplatePageInfo, oDictionaryObj);
                    break;
                case "LIST":// <cms action="list"
                    try
                    {
                        SaveTable(strDataFlag, CMSTagGetData.GetListData(oAttribute, oTemplatePageInfo), oDictionaryTable);
                    }
                    catch// (Exception ex)
                    {
                        //throw ex;
                    }
                    if (oTemplatePageInfo.intPageRealCount > 0 && oTemplatePageInfo.IsCurrentPageDataError == false && oTemplatePageInfo.IsFindPager)
                    {
                        //分页信息初始化
                        DataRow oPageInfo = (DataRow)oDictionaryRow["PageInfo"];
                        int intTotalNum = oTemplatePageInfo.intPageRealCount;
                        int intPageSize = oTemplatePageInfo.intPageSize;
                        oPageInfo["TotalNum"] = intTotalNum;
                        oPageInfo["TotalPage"] = ((intTotalNum % intPageSize == 0) ? (intTotalNum / intPageSize) : ((intTotalNum / intPageSize) + 1));
                        ;
                        oPageInfo["CurrentPage"] = oTemplatePageInfo.intListPagePubIndex;
                        oPageInfo["PageNum"] = intPageSize;
                        string url = oTemplatePageInfo.strPageName + ContentPage.GetPageNameNum(oTemplatePageInfo.intListPagePubIndex) + oTemplatePageInfo.strPageExtName;
                        oPageInfo["URL"] = url;
                        oPageInfo["PageList"] = "";
                    }
                    break;
                case "SQL"://sql 标签
                    try
                    {
                        SaveTable(strDataFlag, CMSTagGetData.GetSqlData(oAttribute, oTemplatePageInfo), oDictionaryTable);
                    }
                    catch// (Exception ex)
                    {
                        //throw ex;
                    }
                    break;
                case "SEARCH": // search 标签
                    try
                    {
                        SaveTable(strDataFlag, CMSTagGetData.GetSearchData(oAttribute, oTemplatePageInfo), oDictionaryTable);
                    }
                    catch// (Exception ex)
                    {
                        //throw ex;
                    }
                    if (oTemplatePageInfo.intPageRealCount > 0 && oTemplatePageInfo.IsCurrentPageDataError == false && oTemplatePageInfo.IsFindPager)
                    {
                        //分页信息初始化
                        DataRow oPageInfo = (DataRow)oDictionaryRow["PageInfo"];
                        int intTotalNum = oTemplatePageInfo.intPageRealCount;
                        int intPageSize = oTemplatePageInfo.intPageSize;
                        oPageInfo["TotalNum"] = intTotalNum;
                        oPageInfo["TotalPage"] = ((intTotalNum % intPageSize == 0) ? (intTotalNum / intPageSize) : ((intTotalNum / intPageSize) + 1));
                        ;
                        oPageInfo["CurrentPage"] = oTemplatePageInfo.intListPagePubIndex;
                        oPageInfo["PageNum"] = intPageSize;
                        string url = oTemplatePageInfo.strPageName + ContentPage.GetPageNameNum(oTemplatePageInfo.intListPagePubIndex) + oTemplatePageInfo.strPageExtName;
                        oPageInfo["URL"] = url;
                        oPageInfo["PageList"] = "";
                    }
                    break;
                case "COMMENT":
                    try
                    {
                        SaveTable(strDataFlag, CMSTagGetData.GetCommentData(oAttribute, oTemplatePageInfo), oDictionaryTable);
                    }
                    catch// (Exception ex)
                    {
                        //throw ex;
                    }
                    if (oTemplatePageInfo.intPageRealCount > 0 && oTemplatePageInfo.IsCurrentPageDataError == false && oTemplatePageInfo.IsFindPager)
                    {
                        //分页信息初始化
                        DataRow oPageInfo = (DataRow)oDictionaryRow["PageInfo"];
                        int intTotalNum = oTemplatePageInfo.intPageRealCount;
                        int intPageSize = oTemplatePageInfo.intPageSize;
                        oPageInfo["TotalNum"] = intTotalNum;
                        oPageInfo["TotalPage"] = ((intTotalNum % intPageSize == 0) ? (intTotalNum / intPageSize) : ((intTotalNum / intPageSize) + 1));
                        ;
                        oPageInfo["CurrentPage"] = oTemplatePageInfo.intListPagePubIndex;
                        oPageInfo["PageNum"] = intPageSize;
                        string url = oTemplatePageInfo.strPageName + ContentPage.GetPageNameNum(oTemplatePageInfo.intListPagePubIndex) + oTemplatePageInfo.strPageExtName;
                        oPageInfo["URL"] = url;
                        oPageInfo["PageList"] = "";
                    }
                    break;
                case "PAGESEARCH":
                    try
                    {
                        SaveTable(strDataFlag, CMSTagGetData.GetPageSearchData(oAttribute, oTemplatePageInfo), oDictionaryTable);
                    }
                    catch// (Exception ex)
                    {
                        //throw ex;
                    }
                    if (oTemplatePageInfo.intPageRealCount > 0 && oTemplatePageInfo.IsCurrentPageDataError == false && oTemplatePageInfo.IsFindPager)
                    {
                        //分页信息初始化
                        DataRow oPageInfo = (DataRow)oDictionaryRow["PageInfo"];
                        int intTotalNum = oTemplatePageInfo.intPageRealCount;
                        int intPageSize = oTemplatePageInfo.intPageSize;

                        oPageInfo["TotalNum"] = intTotalNum;
                        oPageInfo["TotalPage"] = ((intTotalNum % intPageSize == 0) ? (intTotalNum / intPageSize) : ((intTotalNum / intPageSize) + 1));
                        ;
                        oPageInfo["CurrentPage"] = oTemplatePageInfo.intListPagePubIndex;
                        oPageInfo["PageNum"] = intPageSize;

                        string url = string.Empty;
                        if (oTemplatePageInfo.strSearchPageKeys.IsEmpty() == false)
                        {

                            //获取URL，去掉相关的参数
                            url = TRPOP.Common.RequestHelper.GetCurrentUrl();
                            if (url.Contains("&page="))
                            {
                                url = url.Remove(url.IndexOf("&page="));
                            }
                            else if (url.Contains("?page="))
                            {
                                url = url.Remove(url.IndexOf("?page="));
                            }
                        }
                        else
                        {
                            url = oTemplatePageInfo.strPageName + ContentPage.GetPageNameNum(oTemplatePageInfo.intListPagePubIndex) + oTemplatePageInfo.strPageExtName;
                        }


                        oPageInfo["URL"] = url;
                        oPageInfo["PageList"] = "";
                    }
                    break;
                default:
                    break;
            }
        }

        #endregion

        #region 针对不同的页面做不同的处理

        /// <summary>
        /// 根据不同的页面类型做不同的预处理
        /// </summary>
        /// <param name="oTemplatePageInfo"></param>
        /// <param name="m_IDAL"></param>
        public static void PageOper_pre(TemplateDllPageInfo oTemplatePageInfo, IDAL m_IDAL)
        {
            //do nothing..... in 3.0.0.*
        }

        /// <summary>
        /// 根据不同的页面类型做不同的后期处理
        /// </summary>
        /// <param name="oTemplatePageInfo"></param>
        /// <param name="m_IDAL"></param>
        public static void PageOper_end(TemplateDllPageInfo oTemplatePageInfo, IDAL m_IDAL)
        {
            if (oTemplatePageInfo.enumTemplateType == EnumList.TemplateType.ContentPage)
            {
                ContentPageOper_end(oTemplatePageInfo, m_IDAL);
            }
        }

        //内容页的处理 替换内容字段的内容
        private static void ContentPageOper_end(TemplateDllPageInfo oTemplatePageInfo, IDAL m_IDAL)
        {
            // 如果不是内容页、没有主内容字段、当前信息没有主内容字段
            if (oTemplatePageInfo.enumTemplateType != EnumList.TemplateType.ContentPage || string.IsNullOrEmpty(oTemplatePageInfo.strMainField) || oTemplatePageInfo.oContentInfoRow.Table.Columns.Contains(oTemplatePageInfo.strMainField) == false)
                return;

            //内容字段里的图片资源处理
            if (oTemplatePageInfo.oImgResourceType != ImgType.ImgResourceType.Normal && //图片需要进行转换为压缩图片              
                oTemplatePageInfo.oContentInfoRow.Table.Columns.Contains(ImgType.strImgResourceCollectionColumnName) &&//主内容信息包含图片集合
                oTemplatePageInfo.oContentInfoRow[ImgType.strImgResourceCollectionColumnName] is Dictionary<string, Dictionary<ImgType.ImgResourceType, string>>//图片集合符合既定的类型
                )
            {
                ImgResourceHelper oImgResourceHelper = new ImgResourceHelper();
                oImgResourceHelper.oDicSource = oTemplatePageInfo.oContentInfoRow[ImgType.strImgResourceCollectionColumnName] as Dictionary<string, Dictionary<ImgType.ImgResourceType, string>>;
                oTemplatePageInfo.oContentInfoRow[oTemplatePageInfo.strContentMainFied] = oImgResourceHelper.GetSourceContent(oTemplatePageInfo.oContentInfoRow[oTemplatePageInfo.strContentMainFied].ToString(), ImgType.ImgResourceType.Normal, oTemplatePageInfo.oImgResourceType);
            }

            //解析详细内容，详细信息里含有某些特定的语法
            oTemplatePageInfo.oContentInfoRow[oTemplatePageInfo.strMainField] = ContentPageOper_MainFied(oTemplatePageInfo.oContentInfoRow[oTemplatePageInfo.strMainField].ToString());

            //判断分页
            bool blnIsTagCut = false;
            bool blnisLengthCut = false;
            string strContent = oTemplatePageInfo.oContentInfoRow[oTemplatePageInfo.strMainField].ToString();
            int strAutoContentCut = m_IDAL.GetAtuoContentCut();
            TRPOP.CMS.RegAssembly.ContantPageCut oContantPageCut = new ContantPageCut();
            MatchCollection oMatchCollection = oContantPageCut.Matches(strContent);
            if (oMatchCollection.Count > 0)
            {
                blnIsTagCut = true;//如果设定了内容分页标签
            }
            if (strAutoContentCut > 0 && strContent.Length > strAutoContentCut)//如果内容大于系统设置的内容页最大内容限制
            {
                blnisLengthCut = true;//系统设置里设置了内容分页的长度则执行
            }

            //如果标签分页
            if (blnIsTagCut)
            {
                int intIndex = 0;
                oTemplatePageInfo.oContantStrArray.Clear();
                foreach (Match oMatch in oMatchCollection)
                {
                    oTemplatePageInfo.oContantStrArray.Add(strContent.Substring(intIndex, oMatch.Index - intIndex));
                    intIndex = oMatch.Index + oMatch.Length;
                }
                if (oMatchCollection[oMatchCollection.Count - 1].Index + oMatchCollection[oMatchCollection.Count - 1].Length < strContent.Length)
                {
                    oTemplatePageInfo.oContantStrArray.Add(strContent.Substring(oMatchCollection[oMatchCollection.Count - 1].Index + oMatchCollection[oMatchCollection.Count - 1].Length));
                }
            }
            else if (blnisLengthCut)//如果根据内容长度分页
            {
                oTemplatePageInfo.oContantStrArray = TRPOP.Common.CutHtml.GetPageContent(strContent, oTemplatePageInfo.intContentPageLength, true);
            }

            //如果分页，分别替换内容
            if (oTemplatePageInfo.oContantStrArray.Count > 0)
            {
                for (int i = 1; i <= oTemplatePageInfo.oContantStrArray.Count; i++)
                {
                    string test = oTemplatePageInfo.oContantStrArray[i - 1].ToString();
                    oTemplatePageInfo.oContantStrArray[i - 1] = oTemplatePageInfo.strBuildHtml.ToString().Replace("<" + oTemplatePageInfo.strMainField + ">", test);//主内容替换
                    string strPageList = string.Empty, strNextPage = string.Empty, strPrePage = string.Empty;
                    strPageList = ContentPage.GetContentPaging(oTemplatePageInfo.strPageingType, i, oTemplatePageInfo.oContantStrArray.Count, oTemplatePageInfo.strPageName.Replace("{indexid}", oTemplatePageInfo.intCurrentContentID.ToString()), oTemplatePageInfo.strPageExtName, ref strNextPage, ref strPrePage);

                    oTemplatePageInfo.oContantStrArray[i - 1] = oTemplatePageInfo.oContantStrArray[i - 1].ToString().Replace("<PageList>", strPageList);
                    oTemplatePageInfo.oContantStrArray[i - 1] = oTemplatePageInfo.oContantStrArray[i - 1].ToString().Replace("#NextPageURL", strNextPage);
                    oTemplatePageInfo.oContantStrArray[i - 1] = oTemplatePageInfo.oContantStrArray[i - 1].ToString().Replace("#PrePageURL", strPrePage);
                }
            }
            else
            {
                //如果不分页，则只替换strBuildHtml即可
                oTemplatePageInfo.strBuildHtml.Replace("<" + oTemplatePageInfo.strMainField + ">", oTemplatePageInfo.oContentInfoRow[oTemplatePageInfo.strContentMainFied].ToString());
            }

        }

        //内容页内容字段处理
        static IFunc m_IFunc = ITemplateAccess.GetIFuncInstance();//全局函数操作接口

        public static string ContentPageOper_MainFied(string strSource)
        {
            //目前值解析 gethttpurlforlocalfile 函数
            if (strSource.ToLower().Contains("[@gethttpurlforlocalfile(") == false)
                return strSource;

            Dictionary<string, string> oDic = new Dictionary<string, string>();
            foreach (Match oMatch in ConvertTags.oTags_Func.Matches(strSource))
            {
                if (oMatch.Success && !oMatch.Groups["func"].Value.IsEmpty() && oMatch.Groups["func"].Value.Trim().ToLower() == "gethttpurlforlocalfile")
                {
                    ArrayList olistParams = new ArrayList();
                    olistParams.Add(oMatch.Groups["param"].Value.Replace("'", ""));
                    bool isSuccess = false;
                    if (oDic.ContainsKey(oMatch.Value) == false)
                    {
                        oDic.Add(oMatch.Value, IFuncControl.ExecuteFunctionForDll("gethttpurlforlocalfile", olistParams, ref isSuccess, m_IFunc).ToString());
                    }
                }
            }
            foreach (KeyValuePair<string, string> oTemp in oDic)
            {
                strSource = strSource.Replace(oTemp.Key, oTemp.Value);
            }
            return strSource;
        }

        #endregion

    }
}
